$(function(){

	$('.address_list li').click(function(){
		$('.address_list li').removeClass('select');
		$(this).addClass('select');
	})
	$('.item-list .item-plus').click(function(){
		var nub = $(this).siblings('.item-count').val();
		nub = parseInt(nub);
		nub+=1;
		
		var sid = $(this).parents('tr').attr('id');
		var gsid = $(this).parents('tr').attr('data-style');


		
		$.ajax({
			 url:WEB+'?c=Oreder&a=ajax_oreder&stid='+stid,
            type:"post",
            data:{'sid':sid,'nub':nub,'gsid':gsid},
            dataType:"json",
            success:function(data){
            	 $.each(data.goods,function(k,v){
            	$('tr[data-style='+k+']').find('.item-count').val(''+v["num"]+'');
            	$('tr[data-style='+k+']').find('.item-price-all').html('¥'+v["total"]+'');

            	});

            	$('#total_money').html(''+data.total+'')
            }
		});
	});

		$('.item-list .item-minus').click(function(){
		var nub = $(this).siblings('.item-count').val();
		nub = parseInt(nub);
		if(nub>0){
			nub=nub-1;
		}
		
		
		var sid = $(this).parents('tr').attr('id');
		var gsid = $(this).parents('tr').attr('data-style');


		
		$.ajax({
			 url:WEB+'?c=Oreder&a=ajax_oreders&stid='+stid,
            type:"post",
            data:{'sid':sid,'nub':nub,'gsid':gsid},
            dataType:"json",
            success:function(data){
            	 $.each(data.goods,function(k,v){
            	 	 if(v['num']==0){
				$('tr[data-style='+k+']').remove();
						}
            	$('tr[data-style='+k+']').find('.item-count').val(''+v["num"]+'');
            	$('tr[data-style='+k+']').find('.item-price-all').html('¥'+v["total"]+'');
	          
            	});

            	$('#total_money').html(''+data.total+'');
          

            }
		});
	});


		/**
		 * [点击提交订单]
		 * @return {[type]} [description]
		 */
		$('.saveBtn').click(function(){
			// 
			var userInfo  = $('.address_list .select').attr('data-msg');
			if(!userInfo){
				alert("请选择收货地址");
				return false;
			}
			var invoice = $('input[name=invoice]').val();
			var remark = $('input[name=remark]').val();

			$.ajax({
			 url:WEB+'?c=Oreder&a=submit_oreder&stid='+stid,
            type:"post",
            data:{'userInfo':userInfo,'invoice':invoice,'remark':remark},
            dataType:"json",
            success:function(data){
            	
            }
		});




		})
});